/*============================================================================
 * Project    : TaobaoMobile
 * Name       : GuiControlFactory.cpp
 * Author     : Administrator
 * Version    : 1.0
 * Copyright  : Copyright (c) 2009,Aspire-tech technology com, Ltd.
 * All rights reserved.
 * Created on : 2010-9-1 ����08:20:36
 * Description: {description}
 *============================================================================
 */

#include <akniconutils.h> 
//#include <TaobaoMobile.mbg>
#include <avkon.hrh>
#include <avkon.mbg>
#include <aknedsts.h> 
#include <eikenv.h>
#include "GuiControlFactory.h"
#include "Image.h"
#include <eikdef.h>
#include "GameZoneAppUi.h"

static TInt iInputMode = -1;
const TInt KCbaHeight = 51;//28

CCbaImage* CGuiControlFactory::CreateCbaBar(const TRect& aFormRect,const CCoeControl* aParent,
            const TDesC& aLeftText, const TDesC& aRightText)
{
    TPoint pt;
    TRect rect;
    TSize szCba(aFormRect.Width(),KCbaHeight);
    pt.iX = (aFormRect.Width() - aFormRect.Width()) / 2;
    pt.iY = aFormRect.iBr.iY - KCbaHeight;
    rect.SetRect(pt,szCba);
    CCbaImage* CbaBar = CCbaImage::NewL(rect,aParent);
//    CImage* cbaImage = new CImage();
//    cbaImage->ReadImageFromFileL(_L("c:\\data\\GameZone\\cba.png"));
//    CbaBar->SetBackGroundImgL( cbaImage->Bitmap(ETrue) );
//    CbaBar->SetSize(cbaImage->SizeInPixels());
//    delete cbaImage;
//    cbaImage = NULL;
    CbaBar->SetBackGroundImgL( ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iCbaImage->Bitmap(ETrue) );
    CbaBar->SetSize(((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iCbaImage->SizeInPixels());

    CbaBar->SetUsedFont(CEikonEnv::Static()->TitleFont());

    CbaBar->SetLeftTextL(aLeftText);
    CbaBar->SetRightTextL(aRightText);
    return CbaBar;
}

CTitleBar* CGuiControlFactory::CreateTitleBar(const TDesC& aTitleText)
{
    CTitleBar* TitleBar = new ( ELeave ) CTitleBar;
//    CImage* topImage = new CImage();
//    topImage->ReadImageFromFileL(_L("c:\\data\\GameZone\\title.png"));
//    TitleBar->SetPicture( topImage->Bitmap(ETrue) );
//    TitleBar->SetMask(topImage->MaskBitmap(ETrue));
//    TitleBar->SetSize(topImage->SizeInPixels());
//    delete topImage;
//    topImage = NULL;
    TitleBar->SetPicture( ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iTitleImage->Bitmap(ETrue) );
    TitleBar->SetMask(((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iTitleImage->MaskBitmap(ETrue));
    TitleBar->SetSize(((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iTitleImage->SizeInPixels());

    if (aTitleText.Length() > 0)
        TitleBar->setTitleTextL(aTitleText);
    return TitleBar;
}

CInfoBar* CGuiControlFactory::CreateInfoBar()
{
    CInfoBar* infoBar = new(ELeave)CInfoBar;
//    CImage* topImage = new CImage();
//    topImage->ReadImageFromFileL(_L("c:\\data\\GameZone\\info.png"));
//    infoBar->SetPicture( topImage->Bitmap(ETrue) );
//    infoBar->SetMask( topImage->MaskBitmap(ETrue) );
//    infoBar->SetSize(topImage->SizeInPixels());
//    delete topImage;
//    topImage = NULL;
    infoBar->SetPicture( ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iInfoImage->Bitmap(ETrue) );
    infoBar->SetMask( ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iInfoImage->MaskBitmap(ETrue) );
    infoBar->SetSize(((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->iInfoImage->SizeInPixels());
    
    infoBar->SetUsedFont(CEikonEnv::Static()->LegendFont());
    
    return infoBar;
}

CListBox* CGuiControlFactory::CreateListBox(const TRect& aRect, const CCoeControl* aParent)
{
    CListBox* listbox = CListBox::NewL(aRect,aParent);
    listbox->SetFocusedColor(TRgb(117, 113, 112));
    listbox->SetBackgroundColor(TRgb(117, 113, 112));
    TFileName filename = ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->getImageFileName(_L("\\resource\\apps\\backgroup.png"));
    CImage* backImg = new CImage();
    backImg->ReadImageFromFileL(filename);
    CImage* itemSelBgImg = new CImage();
    filename = ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->getImageFileName(_L("\\resource\\apps\\listitem.png"));
    itemSelBgImg->ReadImageFromFileL(filename);
    CImage* noPic = new CImage();
    filename = ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->getImageFileName(_L("\\resource\\apps\\nopic.bmp"));
    noPic->ReadImageFromFileL(filename);
    listbox->SetSelItemBackGroundBitmapL(itemSelBgImg);
    listbox->SetBackGroundBitmap(backImg);
    listbox->AddBitmap(noPic);
    return listbox;
}

CContainerControl* CGuiControlFactory::CreateContainer(const TRect& aRect, const CCoeControl* aParent)
{
    CContainerControl* container = CContainerControl::NewL(aRect, aParent);
    container->setEnableSkin(EFalse);
    CImage* backImg = new CImage();
    TFileName filename = ((CGameZoneAppUi*) (CEikonEnv::Static()->AppUi()))->getImageFileName(_L("\\resource\\apps\\backgroup.png"));
    backImg->ReadImageFromFileL(filename);
    container->SetBackGroundBitmap(backImg);
    return container;
}

void CGuiControlFactory::AddListItemL(CListBox* aOwner, const TDesC& aTitle)
{
    CListItem* item = CListItem::NewL(aOwner);
    item->SetTitleFont(CEikonEnv::Static()->TitleFont());
    item->SetTitleL(aTitle);
    item->SetTitleColor(KRgbWhite);
    item->SetTextColor(KRgbWhite);

    item->SetLayout();
    aOwner->AddListItemL(item);
}

void CGuiControlFactory::AddListItemL(CListBox* aOwner, const TDesC& aID, const TDesC& aName,const TDesC& aXZ,
        const TDesC& aSize,const TDesC& aRq,TInt aBitmap)
{
    CListThemeItem* item = CListThemeItem::NewL(aOwner);
    item->SetBitmap(aOwner->GetBitmap(aBitmap));
    item->SetIDL(aID);
    item->SetTitleL(aName);
    item->SetTextL(aXZ);
    item->SetSizeL(aSize);
    item->SetRQL(aRq);
    
    item->SetTitleColor(KRgbWhite);
    item->SetTextColor(KRgbWhite);

    item->SetTitleFont(CEikonEnv::Static()->SymbolFont());
    item->SetTextFont(CEikonEnv::Static()->SymbolFont());
    
    item->SetLayout();
    aOwner->AddListItemL(item);
}
